package com.mwh.yuantu;

import jakarta.servlet.MultipartConfigElement;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.util.unit.DataSize;

@Slf4j
@SpringBootApplication
@MapperScan(value = { "com.mwh.yuantu.dao.mapper" })
public class YuantuApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(YuantuApplication.class, args);
    }

    //重写configure方法
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(YuantuApplication.class);
    }

    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        // 单个文件最大
        factory.setMaxFileSize(DataSize.ofGigabytes(6)); // KB,MB
        // 设置总上传数据总大小
        factory.setMaxRequestSize(DataSize.ofGigabytes(6));
        return factory.createMultipartConfig();

    }

}
